<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    map键值对，可以看作是升级版的对象
</body>
<script>
    let m = new Map();
    console.log(m, typeof m);
    m.set('name', 'mortal');
    m.set('age', '18');
    m.set('address', '上海');
    m.set('change', function () { console.log('change'); });
    console.log(m);

    let key = {
        school: '北京大学'
    }
    m.set(key, ['北京', '上海']);
    console.log(m);

    // size 长度
    console.log("map的长度", m.size);

    // delete 删除键值对
    m.delete('address');
    console.log(m, m.size);

    // 获取键值对 get
    console.log("获取键值对", m.get('name'));

    // has 判断键值对是否存在
    console.log("判断键值对是否存在", m.has('name'));
    console.log("判断键值对是否存在", m.has('test'));

    // 遍历map
    for (let item of m) {
        console.log("for of 遍历map", item);
    }

    // clear 清空map
    m.clear();
    console.log("map已被清空", m);
</script>

</html>